package cyce.server;

import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.List;

import cyce.file.Directory;
import cyce.file.File;
import cyce.peer.IPeer;
import cyce.peer.IServerPeer;

/**
 * This interface is provided by Servers to Peers
 *
 */
public interface IPeerServer extends Remote {
	/**
	 * This allows a Peer to announce it has joined the network
	 * @throws NotPrimaryServerException 
	 */
	public Directory register(IServerPeer peer, List<File> files) throws RemoteException, NotPrimaryServerException;
	
	/**
	 * This allows a Peer to announce it is leaving the network
	 */
	public void deregister(IServerPeer peer) throws RemoteException;
	
	/**
	 * This allows a peer to add content to the network
	 * @throws NotPrimaryServerException 
	 */
	public void addContent(IServerPeer peer, File file) throws RemoteException, NotPrimaryServerException;
	
	/**
	 * This allows a peer to remove content from the network
	 * @throws NotPrimaryServerException 
	 */
	public void deleteContent(File file) throws RemoteException, NotPrimaryServerException;
	
	/**
	 * This allows a peer to request content locations from the server
	 * @param fileHash Hash value of the file
	 * @return List of peers with the requested file
	 * @throws NotPrimaryServerException 
	 */
	public List<IPeer> requestContent(File file) throws RemoteException, NotPrimaryServerException;
	
	/**
	 * List a peer as having a file available
	 * @param peer The peer
	 * @param file The file
	 * @throws NotPrimaryServerException 
	 */
	public void advertiseFile(IServerPeer peer, File file) throws RemoteException, NotPrimaryServerException;
	
	/**
	 * List a peer as no longer having a file available
	 * @param peer The peer
	 * @param file The file
	 */
	public void unadvertiseFile(IServerPeer peer, File file) throws RemoteException;
	
	/**
	 * This allows a peer to add a directory to the network
	 * @throws NotPrimaryServerException 
	 */
	public void addDirectory(IServerPeer peer, Directory dir) throws RemoteException, NotPrimaryServerException;
	
	/**
	 * This allows a peer to remove a directory from the network
	 * @throws NotPrimaryServerException 
	 */
	public void deleteDirectory(Directory dir) throws RemoteException, NotPrimaryServerException;
}
